from flask import Flask,render_template,request
from mar30.pcUtils import *
app = Flask(__name__)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/getimg")
def getimg():
    return render_template("imgpc.html")

@app.route("/gettext")
def gettext():
    return render_template("pc.html")

@app.route("/login",methods=['POST','GET'])
def login():
    username = request.form['username']
    userpwd = request.form['userpwd']
    if username=='admin':
        if userpwd=='admin123':
            return render_template("pc.html")
        else:
            return "密码错误"
    else:
        return "对不起，当前用户不存在！"

@app.route("/scrawl",methods=['POST','GET'])
def scrawl():
    name = request.form['name']
    url = request.form['targeturl']
    s = pcScrawler()
    targetText = str(s.getTargetText(url,selector='p'))
    return targetText

@app.route("/imgscrawl",methods=['POST','GET'])
def imgscrawl():
    name = request.form['name']
    imgurl = request.form['imgurl']
    q = pcScrawler()
    Img = q.getTargetImg(imgurl)
    return "图片爬取成功"

if __name__=='__main__':
    app.run(host="0.0.0.0",port=5001)